package com.syl.practice.datatype;
import	java.math.BigDecimal;

public class NumberTest {

    public static void main(String[] args) {
        String amt = "100.001万元12";
        String quantity = getQuantity(amt);
        System.out.println(quantity);

        demo01();
    }

    public static void demo01(){
        BigDecimal bigDecimal = new BigDecimal("1000").movePointLeft(4).setScale(2, BigDecimal.ROUND_HALF_UP);
        System.out.println(bigDecimal);
    }

    public static String getQuantity(String regular) {
        int index = 0;
        Boolean flag = false;
        for (int i = 0; i < regular.length(); i++) {
            char c = regular.charAt(i);

            if (".".equals(Character.toString(c))) {
                if (i == 0 || flag) {
                    index = i;
                    break;
                }
                flag = true;
                index = i;
                continue;
            }

            if (Character.isDigit(c)) {
                if (i == regular.length() - 1) {
                    index = i + 1;
                } else {
                    index = i;
                }
                continue;
            } else {
                index = i;
                break;
            }

        }

        String result = regular.substring(0, index);
        if(result.endsWith(".")){
            result = result.substring(0,result.length() -1);
        }
        return result;
    }
}
